package August;

import java.util.Scanner;

public class Day0826 {
    //解读密码
    public static void main1(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()){
            String s = scanner.nextLine();
            char[] ch = s.toCharArray();

            StringBuilder stringBuilder = new StringBuilder();
            for (int i = 0; i < ch.length; i++) {
                if (ch[i]>='0' && ch[i]<='9')
                    stringBuilder.append(ch[i]);
            }
            System.out.println(stringBuilder.toString());
        }
    }


    //走迷宫

    static int [][] fd = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; // 设置上下左右移动
    static char [][] c = new char[10][10];
    static int [][] num = new int [10][10];

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);

        while(input.hasNext()){
            for(int i = 0; i < 10; i++){
                for(int j = 0; j < 10; j++){
                    num[i][j] = Integer.MAX_VALUE;
                }
            }

            for(int i = 0; i < 10; i++){
                c[i] = input.next().toCharArray();
            }
            num[0][1] = 0;
            dfs(0, 1);
            System.out.println(num[9][8]);
        }
    }

    private static void dfs(int x, int y){
        int x1, y1;
        for(int i = 0; i < 4; i++){
            x1 = x + fd[i][0]; y1 = y + fd[i][1];
            if(0 <= x1 && x1 < 10 && y1 < 10
                    && y1 >= 0 && c[x1][y1] == '.'){ // 坐标没有越界，还可以走、
                if(num[x1][y1] > num[x][y] + 1){
                    num[x1][y1] = num[x][y] + 1;
                    dfs(x1, y1);
                }
            }
        }
    }
}
